﻿(function () {
    // 注意JS的绑定顺序，第一组绑定的文件可以用angular.module('MyControllers', []);，后续的文件只能用angular.module('MyControllers')
    var controller = angular.module('MyControllers', []);

    controller.controller('confirmmModal', ['$scope', '$modalInstance', 'items', function ($scope, $modalInstance, items) {
        var methods = {
            ok: function () {
                $modalInstance.close(true);
            },
            cancel: function () {
                $modalInstance.dismiss('cancel');
            },
            text: items
        };
        $.extend($scope, methods);
    }]);

    controller.controller('errorModal', ['$scope', '$modalInstance', 'error', function ($scope, $modalInstance, error) {
        var methods = {
            cancel: function () {
                $modalInstance.dismiss('cancel');
            },
            report: function () {
                $modalInstance.close(true);
            }
        };
        angular.extend($scope, methods, error);
    }]);

    controller.controller('timeController', ['$scope', '$interval', 'utils', function ($scope, $interval, utils) {
        $scope.getTime = function () {
            utils.getServiceTime().success(function (data) {
                $scope.serviceTime = data;
            });
        };

        $scope.autoTime = function () {
            $scope.serviceTime = utils.addSecond($scope.serviceTime);
        };

        // 每分钟到服务端进行核对时间
        var timer1 = $interval(function () {
            $scope.getTime();
        }, 60000);
        //utils.setData({ timer1: timer1 });

        // JS每秒自动时间
        var timer2 = $interval(function () {
            $scope.autoTime();
        }, 1000);
        //utils.setData({ timer2: timer2 });

        $scope.getTime();
    }]);
})()
